// PROGRAMA : SCRPP002
// SISTEMA : SISP - SISTEMA DE INFORMACOES DE SEGURANCA PUBLICA
// IDENTIFICACAO CRIMINAL
// BIBLIOTECA : SISP
// CLIENTE : GEJUSPC - GERENCIA DE ESTADO DA JUSTICA, SEGURANCA
// PUBLICA E CIDADANIA / INSTITUTO DE IDENT.
// OBJETIVO : EMITE ATESTADO DE ANTECEDENTES
// PROGRAMADOR: EDNA PINTO / BRUNO LOPES
// DATA : 03 DE FEVEREIRO DE 1998
// ALTERACAO : 26/08/1998 POR SOLON MIRANDA
// : 12/08/2002 POR SOLON MIRANDA
package br.com.vti.sisp_sicrim.antigo.controller.programa;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;

import net.sf.jasperreports.engine.JRException;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Resource;
import br.com.caelum.vraptor.Result;
import br.com.vti.sisp_sicrim.antigo.controller.relatorios.Scrppa02Report;
import br.com.vti.sisp_sicrim.antigo.controller.tela.Idctea05;
import br.com.vti.sisp_sicrim.antigo.controller.tela.Idctea06;
import br.com.vti.sisp_sicrim.antigo.controller.tela.Idctea07;
import br.com.vti.sisp_sicrim.antigo.controller.tela.Scrtc001;
import br.com.vti.sisp_sicrim.antigo.model.DidCadastro;
import br.com.vti.sisp_sicrim.antigo.model.DidEmissao;
import br.com.vti.sisp_sicrim.antigo.model.Estla001;
import br.com.vti.sisp_sicrim.antigo.model.SicCadastro;
import br.com.vti.sisp_sicrim.antigo.model.SicCadnovo;
import br.com.vti.sisp_sicrim.antigo.model.SicControle;
import br.com.vti.sisp_sicrim.antigo.model.SicEstatistica;
import br.com.vti.sisp_sicrim.antigo.model.SicSenha;
import br.com.vti.sisp_sicrim.antigo.model.SicTabelas;
import br.com.vti.sisp_sicrim.antigo.model.Sislac01;
import br.com.vti.sisp_sicrim.antigo.util.ExceptionProgram;
import br.com.vti.sisp_sicrim.antigo.util.Scrg001;
import br.com.vti.sisp_sicrim.antigo.util.Sessao;
import br.com.vti.sisp_sicrim.antigo.util.UtilBean;

/**
 * Classe : Scrppa02 OBJETIVO : EMITE ATESTADO DE ANTECEDENTES *
 * 
 * @author Incode - Data: mai/2014
 * 
 */
@Resource
@Path("/antigo/scrppa02")
public class Scrppa02 {
	// Views utilizadas
	SicSenha senhaView = new SicSenha();
	DidCadastro vwDidcad = new DidCadastro();
	DidEmissao vwEmissao = new DidEmissao();
	SicCadastro criminalView = new SicCadastro();
	SicCadnovo sicCadnovoView = new SicCadnovo();
	SicTabelas vwTabele = new SicTabelas();
	SicControle vwDvecon = new SicControle();
	SicTabelas vwDvetab = new SicTabelas();
	SicEstatistica vwCadest = new SicEstatistica();
	// Telas/relatorios utilizados
	Idctea05 idctea05;
	Idctea06 idctea06;
	Idctea07 idctea07;
	Scrtc001 scrtc001;
	Scrppa02Report report;
	// Includes utilizados
	Estla001 estla001 = new Estla001();
	Sislac01 sislac01 = new Sislac01();
	// Areas globais / session
	Scrg001 scrg001;
	// Funcoes/subrotinas
	FuncoesGerais funcoes = new FuncoesGerais();
	Result result;
	Sessao sessao;
	Boolean primeiraVez = false;
	Scrppa02 scrppa02Anterior;
	String faseproc = "0";

	// DATA DE APOIO DA TABELA.
	private int j = 0;
	private int i = 0;
	private String chassi = "";
	private String editRg = "";
	private String jNomeMae = "";
	private String jNomePai = "";
	private int data8 = 0;
	// private long jRegger = 0;
	// private int datnas = 0;
	private String[] comun = new String[3];
	private String codmun = "";
	private String vvv = "";
	private String ppp = "";
	private String filia2 = "";
	private String chave = "";
	private String jMunNasc = "";
	private String jMunEnde = "";
	private int jDtNasc = 0;
	private int jDtExp = 0;
	private int jDExp = 0;
	private int jMExp = 0;
	private int jAExp = 0;
	private int jDataExpd = 0;
	private String jVariavel = "";
	private String jVariavel1 = "";
	private long jRegA = 0;
	private String jTitCadastra = "";
	private String jTitFiliacao = "";
	private String jTitE = "";
	private String jTitDtnasc = "";
	private String jTitM1 = "";
	private String jTitM2 = "";
	private int horatemp = 0;
	private int jCont = 0;
	private String jNsenh = "";
	private String datatual = "";
	private int var = 0;
	// VARIAVEIS PARA ESTATISTICA
	private int matr = 0;
	// NOME DO IDENTIFICADO
	private String motida = "";
	private String[] tabm = { "", "   ", "VEI", "CON", "MUL", "   ", "IPV", "ROU", "   ", "   ", "   ", "   ", "   ", "IDC", "ICR", "FUN", "   ", "   " };
	private String chalfa1 = "";
	private String descel1 = "";
	// CONTEM
	private String s1 = "";

	private Idctea05 preMapas() {
		int ind;
		idctea05 = new Idctea05(true, sessao);
		idctea06 = new Idctea06(true, sessao);
		idctea07 = new Idctea07(true, sessao);
		scrtc001 = new Scrtc001(true, sessao);
		Arrays.fill(comun, "");
		// Arrays.fill(nomide, "");
		for (ind = 1; ind <= 3; ind++) {
			scrtc001.setJuseropc(ind, "");
		}
		Arrays.fill(tabm, "");
		idctea05.setDataCorrente(UtilBean.obtemDataDia());

		idctea05.setJregger(0);
		idctea06.setJregger(0);
		idctea07.setJregger(0);
		idctea05.setConf("");
		sessao.getScrg001().setWVltw(13);
		estla001.cpo = 7;
		estla001.esttip = 99;
		sessao.getScrg001().setWProgramaw(this.getClass().getSimpleName());
		data8 = UtilBean.obtemDataCorrente();
		return idctea05;
	}

	public Scrppa02(Result result, Sessao sessao) {
		this.result = result;
		this.sessao = sessao;
	}

	@Post
	public void executar(Idctea05 idctea05, Idctea06 idctea06, Idctea07 idctea07, Scrtc001 scrtc001) {
		try {
			main(idctea05, idctea06, idctea07, scrtc001);
		} catch (Exception e) {
			ExceptionProgram excp = new ExceptionProgram();
			excp.trataErroScrcerro(e, sessao, this.getClass().getSimpleName());
		}
	}

	private void main(Idctea05 pidctea05, Idctea06 pidctea06, Idctea07 pidctea07, Scrtc001 pscrtc001) throws Exception {
		if (pidctea05 == null && pidctea06 == null && pidctea07 == null && pscrtc001 == null) {
			primeiraVez = true;
			// idctea05 = new Idctea05 (primeiraVez);
			idctea05 = preMapas();
			idctea05.setNavegar("../scrppa02/executar");
			result.include("idctea05", idctea05);
			sessao.setAtributo("SCRPPA02", this);
			idctea05.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
			return;
		} else {
			restaurarEstados(pidctea05, pidctea06, pidctea07, pscrtc001);
		}

		if (pidctea05 != null) {
			idctea05.receberTela(false, result);
		}

		if (UtilBean.funcao.equals(UtilBean.ctt_retorna)) {
			Scrpp001 scrpp001 = new Scrpp001(result, sessao);
			scrpp001.executar(null);
		}
		// Par�grafo: fd1()
		senhaView.consultaMatricula(idctea05.getJmatriculaj());
		jCont += 1;
		if (jCont == 3) {

			Scrpp001 scrpp001 = new Scrpp001(result, sessao);
			scrpp001.setMensagem("Voce ultrapassou o numero maximo de tentativas - Tecle <ENTER>");
			scrpp001.executar(null);
			return;
		}
		if (idctea06.getJsenhaj() != senhaView.getSenha()) {
			Scrpp001 scrpp001 = new Scrpp001(result, sessao);
			scrpp001.setMensagem("VERIFIQUE CORRETAMENTE SUA SENHA");
			scrpp001.executar(null);
		}

		sessao.getScrg001().setWNivelw(senhaView.getNivel());
		// #NSENHA N�O FORMATADA NUNCA - IF NUNCA EXECUTADO
		// if (!jNsenh.trim().equals("")) {
		// scrppa02B.enviarReceberTela(false, result);
		// if (jNsenh != scrppa02B.getJwsenh()) {
		// Scrpp001 scrpp001 = new Scrpp001(result, sessao);
		// scrpp001.setMensagem("Confirmacao invalida - Tecla <ENTER>");
		// scrpp001.executar(null);
		// } else {
		// senhaView.setSenha(scrppa02B.getJwsenh());
		// senhaView.atualiza();
		// dao.commit();
		// sessao.getScrg001().setWSenhaw(scrppa02B.getJwsenh());
		// }
		// }

		if (criminalView.registrosProcessados() == 0) {
			Scrpp001 scrpp001 = new Scrpp001(result, sessao);
			scrpp001.setMensagem("Usuario nao cadastrado no sistema");
			scrpp001.executar(null);
			return;
		}
		// dao.rollback();
		if (!UtilBean.funcao.equals(UtilBean.ctt_processa)) {
			idctea05.enviarMensagem(null, "");
			return;
		}
		// DEFINE PRINTER(1)
		// RELATORIO 1 PS=34 LS=80 SG=OFF
		report = new Scrppa02Report();
		report.setPageSize(34);
		report.setLineSize(80);
		// RELATORIO
		for (int i1 = 1; i1 <= 2; i1++) {
			report.setNomide(i1, "");
		}
		jNomeMae = "";
		jNomePai = "";
		report.setFilia1("");
		filia2 = "";
		for (int i1 = 1; i1 <= 2; i1++) {
			comun[i1] = "";
		}
		report.setDatnas(0);
		// qde = 0;
		idctea06.setJdadestrangsn("");
		idctea06.setJdadsn("");
		if (!UtilBean.funcao.equals(UtilBean.ctt_processa)) {
			idctea05.enviarMensagem(null, "");
			return;
		}
		// UtilBean.subStr(s1,0, 3) = 888;
		// s1,3, 12)(sessao.getScrg001().getWMatriculaw());
		// TABELA DE USER-ID/POSTO
		while (vwDvetab.pesquisaTabele(888, (long) sessao.getScrg001().getWMatriculaw())) {
			descel1 = vwDvetab.getDescricaoElem();
			chalfa1 = vwDvetab.getChaveAlfaAcesso();

		}
		if (vwDvetab.registrosProcessados() == 0) {
			// idctea05.enviarMensagem(null,
			// "USUARIO NAO AUTORIZADO PARA EMITIR O ATESTADO" +
			// sessao.getScrg001().getWMatriculaw());
			// UtilBean.salvaAcao("br.com.vti.sisp.mb.programa.Scrpp002"); //
			// STACK
			Scrpp002 scrpp002 = new Scrpp002(result, sessao);
			scrpp002.setMensagem("USUARIO NAO AUTORIZADO PARA EMITIR O ATESTADO" + sessao.getScrg001().getWMatriculaw());
			scrpp002.executar(null, null, null, null);
			return;
		}
		if (idctea05.getConf().trim().equals("") || UtilBean.funcao.equals(UtilBean.ctt_processa)) {
			chave = "";
			if (idctea05.getJregger() != 0) {
				while (vwDvecon.pesquisaNumeroDocumentoTipoDocumentoIn(idctea05.getJregger(), 87, 88)) {
					if (vwDvecon.getTipoDocumento() == 87) {
						idctea05.setMensagem("DOCUMENTO CANCELADO EMISSAO NAO PERMITIDA");
					}
				}
				// REINPUT 'DOCUMENTO CANCELADO EMISSAO NAO PERMITIDA'
				// MARK *#REGGER ALARM
				chassi = "";
				acha(pidctea06, pscrtc001, pidctea07);
				// CALLNAT 'ESTNA001' CPO ESTTIP QDE #VLT# #MATRICULA
				estatistica();
			} else
			// BACKOUT TRANSACTION
			{
				pesquisaCadastroNovo(pidctea06, pscrtc001, pidctea07);
				vwDidcad.setNumeroPosto(Integer.parseInt(UtilBean.subStr(descel1, 38, 3)));
				sicCadnovoView.setNumeroPosto(Integer.parseInt(UtilBean.subStr(descel1, 38, 3)));
				estatistica();
				gravaDidEmissao();
			}
		} else {
			pesquisaCadastroNovo(pidctea06, pscrtc001, pidctea07);
			vwDidcad.setNumeroPosto(Integer.parseInt(UtilBean.subStr(descel1, 38, 3)));
			sicCadnovoView.setNumeroPosto(Integer.parseInt(UtilBean.subStr(descel1, 38, 3)));
			estatistica();
			gravaDidEmissao();
		}
		report.imprimir();
		sessao.setAtributo("SCRPPA02", this);
		result.include("idctea05", idctea05);
		idctea05.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
		UtilBean.salvaAcao("br.com.vti.sisp.mb.programa.Scrpp002"); // STACK
	}

	// FIM

	private boolean acha(Idctea06 pidctea06, Scrtc001 pscrtc001, Idctea07 pidctea07) throws Exception {
		vwDidcad.consultaNumeroRg(idctea05.getJregger());
		if (vwDidcad.totalRegistros() == 0) {
			pesquisaCadastroNovo(pidctea06, pscrtc001, pidctea07);
			UtilBean.salvaAcao("br.com.vti.sisp.mb.programa.Scrpp002"); // STACK
			return true;
		}
		report.setNomide(1, vwDidcad.getNomeIdent());
		jNomePai = vwDidcad.getNomePai();
		jNomeMae = vwDidcad.getNomeMae();
		report.setF1(vwDidcad.getNomePai());
		report.setF2(vwDidcad.getNomeMae());
		if (jNomeMae.trim().equals("")) {
			jNomeMae = "************";
		}
		if (jNomePai.trim().equals("")) {
			jNomePai = "************";
		}

		chave = " ";
		criminal();
		if (chave.equals("N"))
		// REINPUT 'ATENCAO. PESSOA COM ALGUMA RESTRICAO.'
		// MARK *#REGGER ALARM
		// REINPUT 'FAVOR CONSULTAR, ANTES DA ENTREGA DO ATESTADO'
		{
			return false;
		}
		// MARK *#REGGER ALARM

		report.setFilia1(UtilBean.moveSubstring(report.getFilia1(), 118, 3, "A", " E "));
		report.setDatnas(vwDidcad.getDataNasc());
		report.setDatnas((int) funcoes.sissd002(report.getDatnas()));
		vwDvetab.pesq = UtilBean.moveSubstring(vwDvetab.pesq, 0, 3, "N", 1);
		vwDvetab.pesq = UtilBean.moveSubstring(vwDvetab.pesq, 3, 12, "N", vwDidcad.getNomeMunicipioIdent());
		vwDvetab.resp = funcoes.sisst001(1, vwDidcad.getNomeMunicipioIdent(), vwDvetab.resp);
		codmun = vwTabele.resp;
		comun[1] = UtilBean.concatena(codmun, "-", vwDidcad.getUfMunicipioNasc());
		chassi = UtilBean.formataMascara(idctea05.getJregger(), "N", 13, "ZZZZZZZZZ999-9");
		// RELATORIO 1 PS=34 LS=80 SG=OFF
		report.setPageSize(34);
		report.setLineSize(80);
		// RELATORIO
		report.setWnumreg("");
		editRg = "";
		editRg = UtilBean.moveSubstring(editRg, 0, 12, "A", UtilBean.extraiDigitos(idctea05.getJregger(), 13, 1, 12));
		editRg = UtilBean.moveSubstring(editRg, 12, 1, "A", UtilBean.extraiDigitos(idctea05.getJregger(), 13, 13, 1));
		report.setWnumreg(String.format("%12s-%s/SSP-MA", UtilBean.subStr(editRg, 0, 12), UtilBean.subStr(editRg, 12, 1)));
		report.setFx(UtilBean.concatena(report.getF1(), " E"));
		datatual = String.valueOf(UtilBean.obtemDataCorrente());
		report.setDataprint(UtilBean.subStr(datatual, 6, 2) + "/" + UtilBean.subStr(datatual, 4, 2) + "/" + UtilBean.subStr(datatual, 0, 4));
		report.gravaRelatorio(1);

		// RELATORIO
		gravaDidEmissao();
		idctea05.setJregger(0);

		return true;
	}

	private void cadastraNovo(Idctea06 pidctea06) throws Exception {
		if (!idctea06.getEnviada()) {
			idctea06.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
			return;
		}
		if (pidctea06 != null) {
			idctea06.receberTela(false, result);
		}
		sicCadnovoView.setTipoRg("ET");
		sicCadnovoView.setNumeroRg(idctea06.getJregger());
		sicCadnovoView.setNomePessoa(idctea06.getJdadnome());
		sicCadnovoView.setNomePai(idctea06.getJdadpai());
		sicCadnovoView.setNomeMae(idctea06.getJdadmae());
		sicCadnovoView.setDataReg(UtilBean.obtemDataCorrente());
		jDtNasc = UtilBean.inverteData(jDtNasc);
		sicCadnovoView.setDataNasc(jDtNasc);
		sicCadnovoView.setMatriculaFuncAtu(sessao.getScrg001().getWMatriculaw());
		sicCadnovoView.setHoraAtu(Integer.parseInt((new SimpleDateFormat("HHmmssS").format(Calendar.getInstance().getTime()))));
		sicCadnovoView.setUf(idctea06.getJdadpaisorigem());
		sicCadnovoView.setNumeroPosto(Integer.parseInt(UtilBean.subStr(descel1, 38, 3)));
		if (!idctea07.getJdadnumpassaporte().trim().equals("")) {

			sicCadnovoView.setPassaporte(idctea06.getJdadnumpassaporte());
		}
		impAtestaEstrang();
		sicCadnovoView.grava();
		// dao.commit();
		gravaDidEmissao();
	}

	private void criminal() {
		int ind = 0;
		while (criminalView.pesquisaNomeCompletoNomeMae(report.getNomide(1), jNomeMae)) {
			if (criminalView.getStatusReg() != 1)
			// REGISTRO-FEDERAL-CI = #REGGER
			{
				for (ind = 1; ind <= 150; i++) {
					if (!criminalView.getObservacao(ind).trim().equals("")) {
						chave = "N";
					}
				}
			}
		}
	}

	private void impAtestaEstrang() throws Exception {
		report.setNomide(1, idctea06.getJdadnome());
		jNomePai = idctea06.getJdadpai();
		jNomeMae = idctea06.getJdadmae();
		report.setF1(idctea06.getJdadpai());
		report.setF2(idctea06.getJdadmae());
		if (jNomeMae.trim().equals("")) {
			jNomeMae = "************";
		}
		if (jNomePai.trim().equals("")) {
			jNomePai = "************";
		}

		report.setFilia1(UtilBean.moveSubstring(report.getFilia1(), 118, 3, "A", " E "));
		report.setDatnas(sicCadnovoView.getDataNasc());
		report.setDatnas((int) funcoes.sissd002(report.getDatnas()));
		vwDvetab.pesq = UtilBean.moveSubstring(vwDvetab.pesq, 0, 3, "N", 1);
		vwDvetab.pesq = UtilBean.moveSubstring(vwDvetab.pesq, 3, 12, "N", vwDidcad.getNomeMunicipioIdent());
		vwDvetab.resp = funcoes.sisst001(1, vwDidcad.getNomeMunicipioIdent(), vwDvetab.resp);
		codmun = vwTabele.resp;
		comun[1] = UtilBean.concatena(codmun, "-", vwDidcad.getUfMunicipioNasc());
		// RELATORIO 1 PS=34 LS=80 SG=OFF
		report.setPageSize(34);
		report.setLineSize(80);
		// RELATORIO
		report.setWnumreg("");
		editRg = "";
		editRg = UtilBean.moveSubstring(editRg, 0, 12, "A", UtilBean.extraiDigitos(idctea06.getJregger(), 13, 1, 12));
		editRg = UtilBean.moveSubstring(editRg, 12, 1, "A", UtilBean.extraiDigitos(idctea06.getJregger(), 13, 13, 1));
		if (idctea07.getJdadestrangsn().equals("N") || idctea07.getJdadestrangsn().trim().equals("")) {
			report.setWnumreg(String.format("%12s%1s/%s", UtilBean.subStr(editRg, 0, 12), UtilBean.subStr(editRg, 12, 1), idctea06.getJdadpaisorigem()));
			report.setFx(UtilBean.concatena(report.getF1(), " E"));
			datatual = String.valueOf(UtilBean.obtemDataCorrente());
			report.setDataprint(UtilBean.subStr(datatual, 6, 2) + "/" + UtilBean.subStr(datatual, 4, 2) + "/" + UtilBean.subStr(datatual, 0, 4));
			report.gravaRelatorio(2);

			// RELATORIO
		} else {
			datatual = String.valueOf(UtilBean.obtemDataCorrente());
			report.setDataprint(UtilBean.subStr(datatual, 6, 2) + "/" + UtilBean.subStr(datatual, 4, 2) + "/" + UtilBean.subStr(datatual, 0, 4));
			report.gravaRelatorio(3);

			// RELATORIO
		}
		gravaDidEmissao();
		idctea06.setJregger(0);
	}

	private boolean pesquisaCadastroNovo(Idctea06 pidctea06, Scrtc001 pscrtc001, Idctea07 pidctea07) throws Exception {
		// Par�grafo: fdr2()
		sicCadnovoView.consultaNumeroRg(idctea05.getJregger());
		if (sicCadnovoView.totalRegistros() == 0) {
			cadastraNovo(pidctea06);
			return false;
		}

		if (!scrtc001.getEnviada()) {
			scrtc001.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
			return false;
		}
		if (pscrtc001 != null) {
			scrtc001.receberTela(false, result);
		}
		// Analisa condi��es

		if (scrtc001.getJuseropc(1).equals("X")) {
			transfereDadosParaTela();
			impAtestaEstrang();
		} else if (scrtc001.getJuseropc(2).equals("X")) {
			alteraCadastroNovo(pidctea07);
		} else if (scrtc001.getJuseropc(3).equals("X")) {
			excluiCadastroNovo(pidctea07);
		} else {
			transfereDadosParaTela();
			impAtestaEstrang();
		}
		return true;

	}

	private void transfereDadosParaTela() {

		idctea06.setJregger(sicCadnovoView.getNumeroRg());
		idctea06.setJdadnome(sicCadnovoView.getNomePessoa());
		idctea06.setJdadpai(sicCadnovoView.getNomePai());
		idctea06.setJdadmae(sicCadnovoView.getNomeMae());
		datatual = String.valueOf(sicCadnovoView.getDataNasc());
		idctea06.setJdaddia(Integer.parseInt(UtilBean.subStr(datatual, 6, 2)));
		idctea06.setJdadmes(Integer.parseInt(UtilBean.subStr(datatual, 4, 2)));
		idctea06.setJdadano(Integer.parseInt(UtilBean.subStr(datatual, 0, 4)));
		idctea06.setJdadnumpassaporte(sicCadnovoView.getPassaporte());
		idctea06.setJdadpaisorigem(sicCadnovoView.getUf());
		sicCadnovoView.setNumeroPosto(Integer.parseInt(UtilBean.subStr(descel1, 38, 3)));
		if (!sicCadnovoView.getPassaporte().trim().equals("")) {
			idctea06.setJdadestrangsn("S");
		}
	}

	private boolean alteraCadastroNovo(Idctea07 pidctea07) throws Exception {
		transfereDadosParaTela();
		idctea07.setJdadsn("S");
		idctea07.setJtpoperacao("CONFIRMA ALTERACAO (S/N)?");
		idctea07.setJregger(sicCadnovoView.getNumeroRg());

		if (!idctea07.getEnviada()) {
			idctea07.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
			return false;
		}
		if (pidctea07 != null) {
			idctea07.receberTela(false, result);
		}

		// Par�grafo: fdr3()
		sicCadnovoView.consultaNumeroRg(idctea07.getJregger());
		if (sicCadnovoView.totalRegistros() == 0) {
			UtilBean.mensagemTexto("REGISTRO INEXISTENTE NO SIC-CADNOVO, FALAR PARA SOLON RG =", idctea07.getJregger());
			return false;
		}

		sicCadnovoView.setTipoRg("ET");
		sicCadnovoView.setNomePessoa(idctea07.getJdadnome());
		sicCadnovoView.setNomePai(idctea07.getJdadpai());
		sicCadnovoView.setNomeMae(idctea07.getJdadmae());
		sicCadnovoView.setDataReg(UtilBean.obtemDataCorrente());
		jDtNasc = idctea06.getJdaddia() * 1000000 + idctea06.getJdadmes() * 10000 + idctea06.getJdadano();
		sicCadnovoView.setDataNasc(jDtNasc);
		sicCadnovoView.setMatriculaFuncAtu(sessao.getScrg001().getWMatriculaw());
		sicCadnovoView.setUf(idctea07.getJdadpaisorigem());
		sicCadnovoView.setHoraAtu(Integer.parseInt((new SimpleDateFormat("HHmmssS").format(Calendar.getInstance().getTime()))));
		sicCadnovoView.setNumeroPosto(Integer.parseInt(UtilBean.subStr(descel1, 38, 3)));
		if (!idctea07.getJdadnumpassaporte().trim().equals("")) {
			sicCadnovoView.setPassaporte(idctea06.getJdadnumpassaporte());
		}
		sicCadnovoView.atualiza();
		// dao.commit();
		// dao.rollback();
		impAtestaEstrang();

		return true;
	}

	private boolean excluiCadastroNovo(Idctea07 pidctea07) throws JRException, ParseException {
		transfereDadosParaTela();
		idctea07.setJdadsn("S");
		idctea07.setJtpoperacao(" CONFIRMA EXCLUSAO (S/N)?");
		idctea05.setJregger(sicCadnovoView.getNumeroRg());

		if (!idctea07.getEnviada()) {
			idctea07.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
			return false;
		}
		if (pidctea07 != null) {
			idctea07.receberTela(false, result);
		}

		// Par�grafo: fdr4()
		sicCadnovoView.consultaNumeroRg(idctea07.getJregger());
		if (sicCadnovoView.totalRegistros() == 0) {
			UtilBean.mensagemTexto("REGISTRO INEXISTENTE NO SIC-CADNOVO, FALAR PARA SOLON RG =", idctea07.getJregger());
			return false;
		}
		if (sicCadnovoView.getTipoRg().equals("ET")) {
			// RELATORIO 1 PS=34 LS=80 SG=OFF
			report.setPageSize(34);
			report.setLineSize(80);
			// RELATORIO
			report.gravaRelatorio(4);
			sicCadnovoView.exclui();
			// dao.commit();
			UtilBean.mensagemTexto("REGISTRO DELETADO O.K");
		}

		return true;
	}

	private void estatistica() {
		motida = UtilBean.moveSubstring(motida, 0, 3, "A", "IDC");
		motida = UtilBean.moveSubstring(motida, 3, 2, "N", 99);
		motida = UtilBean.moveSubstring(motida, 5, 8, "N", UtilBean.obtemDataCorrente());
		vwCadest.consultaMotida("IDC", 99, UtilBean.obtemDataCorrente(), idctea06.getJmatriculaj());
		mover();
		vwCadest.atualiza();
		// ADD 1 TO VW-CADEST.DINEST-QUANTI (9)
		// dao.commit();

		if (vwCadest.registrosProcessados() == 0) {
			mover();
			vwCadest.grava();
			// dao.commit();
		}
		// dao.rollback();
		// RESET��� VW-CADEST.DINEST-NUMSEQ
		// RESET��� VW-CADEST.DINEST-QUANTI(7)
		// RESET��� VW-CADEST.DINEST-QUANTI(9)
	}

	private void mover() {
		vwCadest.setCodigoModelo("IDC");
		vwCadest.setCodigoTipo(99);
		vwCadest.setDataAtualiz(UtilBean.obtemDataCorrente());
		vwCadest.setMatriculaFunc(idctea06.getJmatriculaj());
		horatemp = Integer.parseInt((new SimpleDateFormat("HHmmss").format(Calendar.getInstance().getTime())));
		vwCadest.setHoraem(horatemp);
		vwCadest.setNumeroPosto(vwDidcad.getNumeroPosto());
		if (idctea07.getJregger() == 0) {
			vwCadest.setNumeroRg(vwDidcad.getNumeroRg());
		} else {
			vwCadest.setNumeroRg(idctea07.getJregger());
		}
		if (idctea07.getJdadnome().trim().equals("")) {
			vwCadest.setNomeId(vwDidcad.getNomeIdent());
		} else {
			vwCadest.setNomeId(idctea07.getJdadnome());
		}
		vwCadest.setNumeroSeq(vwCadest.getNumeroSeq() + 1);
		vwCadest.setQuantTrans(7, vwCadest.getQuantTrans(7) + 1);
	}

	private void gravaDidEmissao() {
		vwEmissao.setRegGeralEmitido(idctea05.getJregger());
		vwEmissao.setNomeIdent(report.getNomide(1));
		vwEmissao.setTipReg(3);
		vwEmissao.setDataEmissao(UtilBean.obtemDataCorrente());
		horatemp = Integer.parseInt((new SimpleDateFormat("HHmmss").format(Calendar.getInstance().getTime())));
		vwEmissao.setHoraEmissaoCarteira(horatemp);
		vwEmissao.setMatriculaFunc(sessao.getScrg001().getWMatriculaw());
		vwEmissao.setNumpos(vwDidcad.getNumeroPosto());
		vwEmissao.setNumeroSerieRg(vwDidcad.getNumeroSerieCart());
		vwEmissao.setUfeder(vwDidcad.getUfMunicipioExp());
		vwEmissao.grava();
		// dao.commit();
		// dao.rollback();
	}

	private void restaurarEstados(Idctea05 pidctea05, Idctea06 pidctea06, Idctea07 pidctea07, Scrtc001 pscrtc001) {
		this.scrppa02Anterior = (Scrppa02) sessao.getAtributo("SCRPPA02");
		if (pidctea05 != null) {
			idctea05 = pidctea05;
		} else {
			idctea05 = this.scrppa02Anterior.idctea05;
		}
		idctea05.setSessao(sessao);
		if (pidctea06 != null) {
			idctea06 = pidctea06;
		} else {
			idctea06 = this.scrppa02Anterior.idctea06;
		}
		idctea06.setSessao(sessao);
		if (pidctea07 != null) {
			idctea07 = pidctea07;
		} else {
			idctea07 = this.scrppa02Anterior.idctea07;
		}
		idctea07.setSessao(sessao);
		if (pscrtc001 != null) {
			scrtc001 = pscrtc001;
		} else {
			scrtc001 = this.scrppa02Anterior.scrtc001;
		}
		scrtc001.setSessao(sessao);
		this.faseproc = this.scrppa02Anterior.faseproc;
	}
}
